//
// Created by lingwu on 2021/4/9.
//

#ifndef DEMO_LINKSTACK_H
#define DEMO_LINKSTACK_H

#endif //DEMO_LINKSTACK_H

#include<iostream>

using namespace std;
typedef char ElemType; // 将栈元素定义为字符型
typedef struct linkNode {
    ElemType date;
    struct linkNode *next;
}LinkStNode;

void InitStack(LinkStNode *&con_link){
//    初始化栈
con_link=(LinkStNode*)malloc(sizeof(LinkStNode));
con_link->next=NULL;
}
bool stackEmpty(linkNode *con_link){
//    判断栈是否为空，为空返回true,否则返回false
    return (con_link->next==NULL);
}
void push(LinkStNode *&con_link,ElemType e){
//    进栈
LinkStNode *s=(LinkStNode*)malloc(sizeof(LinkStNode));
s->date=e;
s->next=con_link->next;
con_link->next=s;
}
bool pop(LinkStNode *&con_link,ElemType &e){
//    出栈
LinkStNode  *s;
    if (con_link->next==NULL)
        return false;
s=con_link->next;
e=s->date;
con_link->next=s->next;
free(s);
    return true;
}
bool getTop(LinkStNode *con_link,ElemType &e){
//  获取栈顶元素 
    if (con_link->next==NULL)
        return false;
    else
        e=con_link->next->date;
    return true;
}
void DestroyStack(LinkStNode *&con_link){
//    销毁栈
LinkStNode *pre=con_link,*p=con_link->next;
    while (p!=NULL){
        free(pre);
        pre=p;
        p=pre->next;
    }
    free(pre);
}